/**
 * 这是用户名片的分享图
 */
const app = getApp()
const imgUrl = app.globalData.imgUrl
let uploadsUrl = app.globalData.uploadsUrl
const rate = 1.0
let offsetLeft = 0*rate;
let offsetTop = 0*rate;
export default class LastMayday {
  palette(qrCodeUrl, data, isShare) { 
    uploadsUrl = app.globalData.uploadsUrl
    if(isShare) offsetTop = -530*rate;
    else offsetTop = 0;
    return ({
      width: 750 * rate +'px',
      height: 1100 * rate +'px',
      background: '#ffffff',
      views: [  
        //商品图片
        {
          type: 'image',
          url: uploadsUrl+data.coverImg,
          css: {
            top: offsetTop + 0 * rate + 'px',
            left: offsetLeft + 0 * rate + 'px',
            width: 750 * rate +'px',
            height: 450 * rate +'px',
          },
        },
     
        
        //标题
        {
          type: 'text',
          text: data.stoName,
          css: { 
            top: offsetTop + 480 * rate +`px`,
            left: offsetLeft + 20 * rate +"px",
            fontSize: 32 * rate +'px',
            color: '#333',
            width: 700 * rate + 'px',
            lineHeight: 50 * rate + 'px',        
            maxLines: 1,
            fontWeight: 'bold'
          }
        },
        //联系人
        {
          type: 'text',
          text: '联系人：' + data.director,
          css: {
            fontSize: 26 * rate + 'px',
            top: offsetTop + 540 * rate + `px`,
            left: offsetLeft + 20 * rate + "px",
            color: '#666', 
          }
        },

        //地址
        {
          type: 'text',
          text: '地址：' + data.prov + data.city + data.disName +data.detailAddress,
          css: {
            fontSize:  28 * rate +'px',
            top: offsetTop + 590 * rate +`px`,
            left: offsetLeft + 20 * rate +"px",
            color: '#666', 
            width: 700 * rate + 'px',
            lineHeight: 40 * rate + 'px'
          }
        },
 

        //灰色细线 
        {
          type: 'rect',
          css: {
            left: offsetLeft + 20 * rate +'px',
            top: offsetTop + 680 * rate +'px',
            color: '#ccc',
            width: 710 * rate +'px',
            height: 2 * rate +'px',
          },
        },
 

        // //小程序码
        {
          type: 'image',
          url: qrCodeUrl,
          css: {
            top: offsetTop + 730 * rate +`px`,
            left: offsetLeft + 280 * rate +`px`,
            width: 200 * rate +'px',
            height: 200 * rate +'px',
          },
        },
        {
          type: 'text',
          text: '扫码或长按识别二维码',
          css: {
            top: offsetTop + 950 * rate +`px`,
            left: offsetLeft + 265 * rate +"px",
            fontSize: 24 * rate +'px',
            color: '#A6A6A6',
          },
        },
      ],
    });
  }
}


//计算出阴影的宽度
function calc_shadow_width(text) {
  return text.length*56+48;
}

function getShadow(text, row, left_text) {
  left_text = left_text || ""
  var left_width = left_text ? calc_shadow_width(left_text)+24:0
  return {
    type: 'rect',
    css: {
      top: `${444+(row-1)*128}px`,
      left: `${48 + left_width}px`,
      color: '#FFC5C5',
      borderRadius: '32px',
      width: `${calc_shadow_width(text)}px`,
      height: '96px',
    },
  }
}

function getText(text, row, left_text) {
  left_text = left_text || ""
  var left_width = left_text ? calc_shadow_width(left_text) + 24 : 0
  return {
    type: 'text',
    text: text,
    css: {
      top: `${462 + (row - 1) * 128}px`,
      left: `${72 + left_width}px`,
      fontSize: '56px',
      fontWeight: 'normal',
      color: '#333',      
    },
  }
}